package com.wc.alorithm_blue_bridge._数据结构.线段树.Q1133;

import java.io.*;

/**
 * @Author congege
 * @Description 区间修改、区间求和
 * https://www.lanqiao.cn/problems/1133/learning/?page=1&first_category_id=1&second_category_id=8
 * @Date Created in 2023/12/6-21:51
 */
public class Main {
    static int maxN = (int) 1e5 + 10;

    static class Node {
        int l;
        int r;
        long sum;
        long lz;
    }

    static int[] array;
    static Node[] tree;

    static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    public static void main(String[] args) {
        int n = nextInt();
        int m = nextInt();
        array = new int[n + 1];
        tree = new Node[4 * (n + 1)];
        for (int i = 1; i <= n; i++) {
            array[i] = nextInt();
        }
        build(1, 1, n);
        while (m-- > 0) {
            int op = nextInt();
            int l = nextInt();
            int r = nextInt();
            if (op == 1) {
                int x = nextInt();
                add(1, l, r, x);
            } else {
                out.println(querySum(1, l, r));
            }
        }
        out.flush();
    }

    public static int nextInt() {
        try {
            in.nextToken();
        } catch (Exception e) {
            return -1;
        }
        return (int) in.nval;
    }

    public static void pushDown(int p) {
        if (tree[p].lz != 0) {
            int lc = p << 1;
            int rc = lc + 1;
            tree[lc].lz += tree[p].lz;
            tree[rc].lz += tree[p].lz;
            tree[lc].sum += tree[p].lz * (tree[lc].r - tree[lc].l + 1);
            tree[rc].sum += tree[p].lz * (tree[rc].r - tree[rc].l + 1);
            tree[p].lz = 0;
        }
    }

    public static void build(int p, int l, int r) {
        tree[p] = new Node();
        tree[p].l = l;
        tree[p].r = r;
        if (l == r) {
            tree[p].sum = array[l];
            return;
        }
        int lc = p << 1;
        int rc = lc + 1;
        int mid = (l + r) >> 1;
        build(lc, l, mid);
        build(rc, mid + 1, r);
        tree[p].sum = tree[lc].sum + tree[rc].sum;
    }

    public static void add(int p, int l, int r, int x) {
        if (tree[p].l >= l && tree[p].r <= r) {
            tree[p].sum += (long) x * (tree[p].r - tree[p].l + 1);
            tree[p].lz += x;
            return;
        }
        pushDown(p);
        int lc = p << 1;
        int rc = lc + 1;
        int mid = (tree[p].l + tree[p].r) >> 1;
        if (mid >= l) {
            add(lc, l, r, x);
        }
        if (mid + 1 <= r) {
            add(rc, l, r, x);
        }
        tree[p].sum = tree[lc].sum + tree[rc].sum;
    }

    public static long querySum(int p, int l, int r) {
        if (tree[p].l >= l && tree[p].r <= r) {
            return tree[p].sum;
        }
        if (tree[p].l > r || tree[p].r < l) {
            return 0;
        }
        pushDown(p);
        long ans = 0;
        int lc = p << 1;
        int rc = lc + 1;
        int mid = (tree[p].l + tree[p].r) >> 1;
        if (mid >= l) {
            ans += querySum(lc, l, r);
        }
        if (mid + 1 <= r) {
            ans += querySum(rc, l, r);
        }

        return ans;
    }
}
